package com.hospital.serviceImpl;

import com.hospital.dao.UserDepartmentMapper;
import com.hospital.dao.UserMapper;
import com.hospital.entity.User;
import com.hospital.entity.UserDepartment;
import com.hospital.service.UserDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class UserDepartmentServiceImpl implements UserDepartmentService {
    @Autowired
    private UserDepartmentMapper userDepartmentMapper;

    /**
     * 修改用户科室方法
     *
     * @param userId       用户id
     * @param departmentId 科室id
     * @return 修改状态
     */
    @Override
    public Integer UpdateDepartment(Integer userId, Integer departmentId, Integer deleteState) {
        Integer state = userDepartmentMapper.UpdateDepartment(userId, departmentId, deleteState);
        return state;
    }

    /**
     * 查询用户对应的所有科室
     *
     * @param id userId
     * @return 用户对应的所有科室信息
     */
    @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
    @Override
    public List<UserDepartment> SelectDepartment(Integer id, Integer responsibleDepartmentId) {
        List<UserDepartment> list = userDepartmentMapper.SelectDepartment(id, responsibleDepartmentId);
        return list;
    }

    /**
     * 添加用户对应的科室
     *
     * @param userDepartment 用户对应科室对象
     * @return 添加状态
     */
    @Override
    public Integer InsertDepartment(UserDepartment userDepartment) {
        Integer state = userDepartmentMapper.InsertDepartment(userDepartment);
        return state;
    }

    /**
     * 删除用户对应的科室
     *
     * @param userId 用户id
     * @return 删除状态
     */
    @Override
    public Integer DeleteDepartment(Integer userId) {
        Integer state = userDepartmentMapper.DeleteDepartment(userId);
        return state;
    }
    /**
     * 用户姓名与科室查询
     *
     * @param name       用户姓名
     * @param department 科室
     * @return 用户信息
     */
    @Override
    public List<User> SelectByNameDepartment(String name, String department) {
        List<User> users = userDepartmentMapper.SelectByNameDepartment(name, department);
        return users;
    }

    /**
     * 查所有科室
     *
     * @return 集合中的科室对象
     */
    @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
    @Override
    public List<UserDepartment> SelectAllDepartment() {
        List<UserDepartment> userDepartments = userDepartmentMapper.SelectAllDepartment();
        return userDepartments;
    }
}
